package com.kll.carolinehmibiz.presentation.presenter

import android.content.Context
import com.kll.carolinehmibiz.OperationManager
import com.kll.carolinehmibiz.model.OperateListener
import com.kll.carolinehmibiz.net.bean.GetSystemMenuDetailResponse
import com.kll.carolinehmibiz.net.bean.GetSystemMenuResponse
import com.kll.carolinehmibiz.presentation.BasePresenter
import com.kll.carolinehmibiz.presentation.listener.SecondaryMenuProtocol

class SecondaryMenuPresenter(context: Context, mView: SecondaryMenuProtocol.IView): BasePresenter(context), SecondaryMenuProtocol.IPresenter {
    private var mView: SecondaryMenuProtocol.IView? = mView
    private var getArticleIsBusying = false

    override fun loadSystemMenu(parentId: Int) {
        OperationManager.getInstancce().getSystemAllMenus(parentId, object: OperateListener {
            override fun onSuccess(state: Int, obj: Any?) {
                if (state == 200) {
                    mView?.getSystemMenuSuccessed(obj as ArrayList<GetSystemMenuResponse>)
                }
            }
            override fun onFail(code: Int, message: String) {
                mView?.getSystemMenuFailed(code, message)
            }

        })
    }

    override fun getArticle(menuId: Int) {
        if (getArticleIsBusying) return
        getArticleIsBusying = true
        OperationManager.getInstancce().getSystemMenuDetail(menuId, object : OperateListener {
            override fun onSuccess(state: Int, obj: Any?) {
                if (state == 200) {
                    getArticleIsBusying = false
                    mView?.getArticleSuccessed(obj as ArrayList<GetSystemMenuDetailResponse>)
                }
            }

            override fun onFail(code: Int, message: String) {
                getArticleIsBusying = false
                mView?.getArticleFailed(code, message)
            }

        })
    }

}